<include file="public:header" />

<div class="container">

		<p>&nbsp;</p>
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>IMEI：</strong></div>
			<div class="col-xs-7" >{$v.imei}</div>
		</div>	
		<div class="row">	
			<div class="col-xs-5 text-right" ><strong>机型：</strong></div>
			<div class="col-xs-7" >{$v.model}</div>
		</div>	
		
		<hr />
		
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>录入时间：</strong></div>
			<div class="col-xs-7" >{:date('Y-m-d H:i:s', $v['salesCreateTime'])}</div>
		</div>
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>录入人：</strong></div>
			<div class="col-xs-7" >{$v.toRealName}</div>
		</div>
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>营业厅：</strong></div>
			<div class="col-xs-7" >{$v.toUserStoreName}</div>
		</div>
		
		<hr />
		
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>申诉时间：</strong></div>
			<div class="col-xs-7" >{:date('Y-m-d H:i:s', $v['disputeCreateTime'])}</div>
		</div>
		<div class="row">	
			<div class="col-xs-5 text-right" ><strong>发起人：</strong></div>
			<div class="col-xs-7" >{$v.createRealName}</div>
		</div>	
		<div class="row">
			<div class="col-xs-5 text-right" ><strong>营业厅：</strong></div>
			<div class="col-xs-7" >{$v.createUserStoreName}</div>
		</div>

		<hr />
		
		<div class="row">	
			<div class="col-xs-5 text-right" ><strong>处理进度：</strong></div>
			<div class="col-xs-7" >{$v.progress}</div>
			<if condition="$v['history']['content']">
				<div class="col-xs-5 text-right" ><strong>理由：</strong></div>
				<div class="col-xs-7" >{$v.history.content}</div>
			</if>
			<if condition="in_array($v['status'], array(4,5,6,7))">
				<div class="col-xs-5 text-right" ><strong>录入最终归属：</strong></div>
				<div class="col-xs-7" >{$v.owner}</div>
			</if>
		</div>	
		
		<if condition="($v['toUserId'] eq $user['id']) AND ($v['status'] eq 1)">
			<hr />
			<div class="msg msg-6 alert alert-danger">
			</div>
			<a class="btn btn-danger btn-block" href="javascript:void(0)" onclick="setStatus(6);">解决冲突</a>
			<p>&nbsp;</p>
			<pre>点击“解决冲突”按钮后，您录入的IMEI：{$v.imei} 将归申诉发起者{$v.createRealName}所有</pre>
			<hr />
			<form id="formBox2"  method="post" action="__ROOT__?g=api&m=sales&a=setDisputeStatus" >
				<input type="hidden" name="id" value="{$v.id}" />
				<input type="hidden" name="historyStatus" value="{$v.status}" />
				<input type="hidden" name="newStatus" value="2" />
				<p class="text-center">冲突无效理由</p>
				<textarea class="form-control" rows="3" name="content"></textarea>
				<p>&nbsp;</p>
				<div class="msg msg-2 alert alert-danger">
				</div>
				<button type="submit" class="btn btn-primary btn-block">冲突无效</button>
			</form>
		</if>
		
		<if condition="($v['createUserId'] eq $user['id']) AND ($v['status'] eq 2)">
			<hr />
			<div class="msg msg-3 msg-7 alert alert-danger">
			</div>
			<pre>您是否同意{$v.toRealName}的处理方式</pre>
			<div class="btn-group btn-group-justified">
				<a class="btn btn-primary" href="javascript:void(0)" onclick="setStatus(3);">不同意</a>
				<a class="btn btn-danger" href="javascript:void(0)" onclick="setStatus(7);">同意</a>
			</div>
		</if>
		
		<if condition="$v['status'] eq 3 AND (($v['createUserCityId'] eq $user['cityId'][0]) OR ($v['toUserCityId'] eq $user['cityId'][0]))">
			<hr />
			<form id="formBox4"  method="post" action="__ROOT__?g=api&m=sales&a=setDisputeStatus" >
				<input type="hidden" name="id" value="{$v.id}" />
				<input type="hidden" name="historyStatus" value="{$v.status}" />
				<input type="hidden" name="newStatus" value="4" />
				<p class="text-center">申诉无效理由</p>
				<textarea class="form-control" rows="3" name="content"></textarea>
				<span class="help-block">选择“申诉无效”，则 IMEI 仍为“{$v.toRealName}”所有。</span>
				<div class="msg msg-4 alert alert-danger">
				</div>
				<button type="submit" class="btn btn-danger btn-block">申诉无效</button>
			</form>
			
			<hr />
			<form id="formBox5"  method="post" action="__ROOT__?g=api&m=sales&a=setDisputeStatus" >
				<input type="hidden" name="id" value="{$v.id}" />
				<input type="hidden" name="historyStatus" value="{$v.status}" />
				<input type="hidden" name="newStatus" value="5" />
				<p class="text-center">申诉有效理由</p>
				<textarea class="form-control" rows="3" name="content"></textarea>
				<span class="help-block">选择“申诉有效”，则 IMEI 转为“{$v.createRealName}”所有。</span>
				<div class="msg msg-5 alert alert-danger">
				</div>
				<button type="submit" class="btn btn-primary btn-block">申诉有效</button>
			</form>
		</if>
		
		<p>&nbsp;</p>
</div>

<div id="myModal" class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<form id="formBox"  method="post" action="__ROOT__?g=api&m=sales&a=setDisputeStatus" >
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-body">
					<p>…</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button type="submit" class="btn btn-primary">确定</button>
				</div>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript">

	$('.msg').hide();
	
	// 设置工号状态
	function setStatus(newStatus){
		var fromContent = '<input type="hidden" name="id" value="{$v.id}" />';
	
		if(newStatus === 6){
			fromContent += '<input type="hidden" name="historyStatus" value="{$v.status}" />';
			fromContent += '<input type="hidden" name="newStatus" value="'+newStatus+'" />';
			fromContent += '<p><strong>您确定解决冲突吗？IMEI将归{$v.createRealName}所有</strong></p>';
		}
		if(newStatus === 3){
			fromContent += '<input type="hidden" name="historyStatus" value="{$v.status}" />';
			fromContent += '<input type="hidden" name="newStatus" value="'+newStatus+'" />';
			fromContent += '<p><strong>此 IMEI 申诉记录将提交给市场总监处理，您确定吗？</strong></p>';
		}
		if(newStatus === 7){
			fromContent += '<input type="hidden" name="historyStatus" value="{$v.status}" />';
			fromContent += '<input type="hidden" name="newStatus" value="'+newStatus+'" />';
			fromContent += '<p><strong>此 IMEI 申诉记录将结单，录入者仍为{$v.toRealName}，您确定吗？</strong></p>';
		}

		$("#myModal .modal-body").html(fromContent);
		$('#myModal').modal("show");
	}
	
	//绑定一个指定的表单
    $('#formBox').ajaxForm({ 
            //设置传输的数据类型
            dataType:  'json', 
            //请求成功后，调用的回调函数
            success:  back
    }); 
	
	//绑定一个指定的表单
    $('#formBox2').ajaxForm({ 
            //设置传输的数据类型
            dataType:  'json', 
            //请求成功后，调用的回调函数
            success:  back
    }); 
	
	//绑定一个指定的表单
    $('#formBox4').ajaxForm({ 
            //设置传输的数据类型
            dataType:  'json', 
            //请求成功后，调用的回调函数
            success:  back
    }); 
	
	//绑定一个指定的表单
    $('#formBox5').ajaxForm({ 
            //设置传输的数据类型
            dataType:  'json', 
            //请求成功后，调用的回调函数
            success:  back
    }); 

    function back(project){
		$('.msg').hide();
        if(project.status === 200){
			location.href="__ROOT__/index.php?g=api&m=sales&a=disputeDetail&id={$v.id}";
        }else{
			$('#myModal').modal("hide");
			
			$('.msg-'+project.data.status).html('<strong>'+project.msg+'</strong>');
			$('.msg-'+project.data.status).show();
        }
    }

</script>

<include file="public:footer" />